home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9627 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: passing arrays and returning structs
  5. Date: 12 Mar 1996 08:35:43 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4i3d0v$96p@sparcserver.lrz-muenchen.de>
  9. References: <4i2128$69d@news2.acs.oakland.edu> <4i27eo$202@newsgate.dircon.co.uk>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. sridgway@dircon.co.uk (Steven Ridgway) writes:
  13.  
  14. >jggoslin@vela.acs.oakland.edu (Monument) wrote:
  15.  
  16. >>struct Message transitive_closure(int matrix[]);
  17.  
  18. [and later in the same source file]
  19.  
  20. >>struct Message* transitive_closure(int matrix[])
  21. >>{
  22.  
  23. [Implementation of transitive closure edited]
  24.  
  25. >>}
  26. >>===client.c===
  27.  
  28. >>===ERRORS===
  29. >>/usr/lib/cmplrs/cc/cfe: Error: client.c, line 73: redeclaration of 'transitive_closure'; previous declaration at line 11 in file 'client.c'
  30. >> struct Message* transitive_closure(int matrix[])
  31. [other error messages edited]
  32. >>Stop.
  33. >>===ERRORS===
  34.  
  35. >Hi,
  36.  
  37. >You have at least three problems here.
  38.  
  39. >1.     You should prototype your function transitive_closure before
  40. >you use it. ie add the line :
  41. >struct Message* transitive_closure(int matrix[]);
  42.  
  43. How would you interpret the line
  44.  
  45.   struct Message transitive_closure(int matrix[]);
  46.  
  47. It looks like a function prototype to me, but it does not match the 
  48. function definition. And _that_ is at least part of the real problem.
  49.  
  50. >at the top of your file or in a header (before you reference it but
  51. >after you define Message anyway).
  52.  
  53. >Without this the compiler assumes it returns int, then whines when you
  54. >define it as something else.
  55.  
  56. The compiler clearly reports that there _is_ a previous declaration
  57. for the function in line 11. This implies that there has been a
  58. previous declaration, doesn't it?
  59.  
  60. [correct analysis of a problem with returning a pointer to a local
  61. variable with automatic storage edited]
  62.  
  63. Kurt
  64. -- 
  65. | Kurt Watzka                             Phone : +49-89-2180-6254
  66. | watzka@stat.uni-muenchen.de
  67. | ua302aa@sunmail.lrz-muenchen.de
  68.